package org.jeecg.modules.hxrencai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.hxrencai.bo.*;
import org.jeecg.modules.hxrencai.dto.MergeDto;
import org.jeecg.modules.hxrencai.entity.University;
import org.jeecg.modules.hxrencai.mapper.UniversityMapper;
import org.jeecg.modules.hxrencai.service.IUniversityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description: 高校信息
 * @Author: jeecg-boot
 * @Date: 2019-11-24
 * @Version: V1.0
 */
@Service
public class UniversityServiceImpl extends ServiceImpl<UniversityMapper, University> implements IUniversityService {
    @Autowired
    private UniversityMapper universityMapper;

    @Override
    public List<AreaBo> queryProvinceNumGroupByArea(String importType) {
        return universityMapper.queryProvinceNumGroupByArea(importType);
    }

    @Override
    public List<NumBo> getFrontThreeByProvince(String province) {
        if (StringUtils.isNotBlank(province) && province.startsWith("福建")) {
            return universityMapper.getFjFrontThree();
        } else {
            return universityMapper.getFrontThreeByProvince(province);
        }
    }

    @Override
    public int getSchoolByProvince(String province) {
        return universityMapper.getSchoolByProvince(province);
    }

    @Override
    public ThreeDataBo queryProvinceTotalBknum(String province) {
        return universityMapper.queryProvinceTotalBknum(province);
    }

    @Override
    public SchoolBo queryFjThreeNum() {
        SchoolBo schoolBo = new SchoolBo();
        schoolBo.setGzNum(universityMapper.queryFjThreeNum("1"));
        schoolBo.setZzNum(universityMapper.queryFjThreeNum("6"));
        schoolBo.setBkNum(universityMapper.queryFjThreeNum("2"));
        return schoolBo;
    }

    @Override
    public ThreeDataBo queryFjTotalNum() {
        return universityMapper.queryFjTotalNum();
    }

    @Override
    public List<NumBo> getProvinceRank(String profession) {
        List<NumBo> list = universityMapper.getProvinceRank(profession);
        for (NumBo numBo : list) {
            String name = numBo.getName();
            if (StringUtils.isNotBlank(name) && name.endsWith("省")) {
                name = name.substring(0, name.length() - 1);
                numBo.setName(name);
            }
        }
        return list;
    }

    @Override
    public List<SchoolListBo> getSchoolNamePage(MergeDto dto) {
        int n = dto.getPageNo() == null ? 1 : dto.getPageNo();
        int s = dto.getPageSize() == null ? 10 : dto.getPageSize();
        List<SchoolNameBo> names = universityMapper.getSchoolNamePage(n, s, dto);
        List<SchoolListBo> schoolList = new ArrayList<>();
        for (SchoolNameBo nameBo : names) {
            SchoolListBo listBo = new SchoolListBo();
            listBo.setSchoolName(nameBo.getSchoolName());
            if (StringUtils.isNotBlank(nameBo.getIds()) && nameBo.getIds().contains(",")) {
                List<String> collect = Stream.of(nameBo.getIds().split(",")).collect(Collectors.toList());
                listBo.setIds(collect);
            }
            if (StringUtils.isNotBlank(nameBo.getProfessions()) && nameBo.getProfessions().contains(",")) {
                List<String> collect = Stream.of(nameBo.getProfessions().split(",")).collect(Collectors.toList());
                listBo.setProfessions(collect);
            }
            schoolList.add(listBo);
        }
        return schoolList;
    }
}
